<!-- eslint-disable no-template-curly-in-string -->
<template>
  <div class="init-container">
    <Input
      :value="showValue"
      :disabled="disabled"
      :clearable="clearable"
      :placeholder="placeholder"
      type="textarea"
      @on-clear="onClear"
      @on-blur="onBlur"
      @input="input"
    />
  </div>
</template>

<script lang="ts">
import { T_srv, ifs, vue } from '@/services';

@T_srv.comp
export default class subQueryInput extends vue {
  @T_srv.prop({
    type: Boolean,
    default: true
  })
  disabled: boolean;

  @T_srv.prop({
    type: Boolean,
    default: true
  })
  clearable: boolean;

  @T_srv.prop({
    type: String,
    default: ''
  })
  placeholder: string;

  @T_srv.prop({ required: true })
  value: any;

  /* 组件名 */
  private name: string = 'subQueryInput';

  private funName: string = '';

  private G_compName: string = this.name;

  /* 组件箱信息对象 */
  private GT_compBoxInfo: ifs.I_compBoxInfo;

  /* 组件箱对象 */
  private GT_compBox: ifs.I_compBox;

  /* 组件箱识别ID */
  private G_compID: string;

  /* 指挥部 */
  /* 遮罩 */
  public isMask: boolean = false;

  // eslint-disable-next-line no-template-curly-in-string
  private doubleQuotes = '${doubleQuotes}'; // 单引号占位符

  // eslint-disable-next-line no-template-curly-in-string
  private singleQuotes = '${singleQuotes}'; // 双相号占位符

  private regExSingleQuotes = new RegExp(
    this.singleQuotes.replace('$', '\\$'),
    'g'
  );

  private regExDoubleQuotes = new RegExp(
    this.doubleQuotes.replace('$', '\\$'),
    'g'
  );

  get showValue() {
    return this.value
      .replace(this.regExSingleQuotes, "'")
      .replace(this.regExDoubleQuotes, '"');
  }

  onClear(e) {
    const v = e.replace(/[\r\n]/g, ' ').trim();
    this.$emit('on-clear', v);
  }

  onBlur(e) {
    const v = e.target.value.replace(/[\r\n]/g, ' ').trim();
    this.$emit('on-blur', v);
  }

  input(e) {
    this.$emit(
      'input',
      e.replace(/'/g, this.singleQuotes).replace(/"/g, this.doubleQuotes)
    );
  }
}
</script>
<style lang="scss" scoped></style>
